<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/22 0022
 * Time: 10:24
 */

namespace app\admin\controller;


use think\Controller;

class news extends Controller
{
    public function index(){
        $data = db("news")->select();
        $this->assign([
            'data' => $data
        ]);
        return view("index");
    }
    public function add(){
        if(request()->post()){
            $param = request()->except('image');
            $file = request()->file('image');
            $info=$file->move( './static/images');
            $filename=str_replace("\\","/",$info->getSaveName());
            $image = '/static/images/'.$filename;
//            return $param['anchor'];
            $data = [
                'title' => $param['title'],
                'author' => $param['anchor'],
                'source' => $param['source'],
                'descr' => $param['descr'],
                'content' => $param['content'],
                'uptime' => date("Y-m-d H:i:s"),
                'image' => $image
            ];
            $row = db("news")->insert($data);
            if($row){
                return 200;
            }else{
                return -1;
            }
        }
        return view("add");
    }
    public function detail(){
        $id = input("id");
        $data = db("news")->where("id",$id)->find();
        $this->assign([
            'data' => $data
        ]);
//        dump($data['descr']);
        return view("detail");
    }
}